﻿using System;
using System.IO;
using System.Linq;
using System.Threading;

namespace NEATlib
{
    public class CancerDataProvider
    {
        private static CancerDataCollection Data = new CancerDataCollection();

        public static DataCollection GetCollection()
        {
            if (Data.SamplesCount == 0)
                Data.LoadData(File.ReadAllLines("cancer1.dt"));
            return Data;
        }
    }

    public class CancerDataCollection : DataCollection
    {
        public override void LoadData(string[] lines)
        {
            //input
            //0.2 0.1 0.1 0.1 0.2 0.1 0.2 0.1 0.1 
            //output
            //1 0
            Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");

            for (var l = 7; l < lines.Length; l++)
            {
                var line = lines[l];
                var strAttributes = line.Split(' ');

                var _values = new double[9];

                double value;
                for (int i = 0; i < 9; i++)
                {
                    Double.TryParse(strAttributes[i], out value);
                    _values[i] = value;
                }
                Double.TryParse(strAttributes.Last(), out value);

                var expectedOut = new double[1];

                Double.TryParse(strAttributes[9], out value);
                expectedOut[0] = value;


                _dataCollection.Add(new DataItem()
                {
                    DataSeries = _values,
                    ExpectedOutput = expectedOut
                });
            }
        }
    }
}
